<?php

namespace App\Http\Middleware;

use App\Lib\Code;
use App\Services\ApiResponseService;
use Closure;
use Illuminate\Support\Facades\Auth;

class CompleteAuthInfoJWT
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $user = Auth::user();
        if ($user->is_profiled && $user->is_remitted) {
            return $next($request);
        } else {
            if (!$user->is_profiled) {
                return ApiResponseService::showError(Code::PROFILE_INFO_UNCOMPLETE);
            }
            return ApiResponseService::showError(Code::REMIT_INFO_UNCOMPLETE);
        }
    }
}
